package com.minivision.sdktestdemo.ui;

import android.os.Handler;
import android.os.Message;

import com.minivision.sdktestdemo.service.MusicService;

import java.lang.ref.WeakReference;

/**
 * Created by devtang on 2016/4/26.
 */
public class MusicControlHandler extends Handler {
    public interface onProgressUpdated {
        public void update(int value, int max);

        public void startUpdate();

        public void stopUpdate();
    }

    private WeakReference<onProgressUpdated> mListener;

    public MusicControlHandler(onProgressUpdated listener) {
        mListener = new WeakReference<onProgressUpdated>(listener);
    }

    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case MusicService.UPDATE_PROGRESS:
                if (mListener.get() != null) {
                    mListener.get().update(msg.arg1, msg.arg2);
                }
                break;
        }
    }
}
